﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;

namespace PokemonTCGDL
{
    public class DecksDL : PokemonTCGDL
    {
        public static DataTable GetDecksByUsername(string Username)
        {
            SqlDataReader dr = null;
            DataTable dt = new DataTable();
            using (SqlConnection sqlConn = GetConnection())
            {
                try
                {
                    sqlConn.Open();
                    SqlCommand cmd = new SqlCommand();
                    cmd.Connection = sqlConn;
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.CommandText = "spGetDecksByUsername";
                    SqlParameter param = new SqlParameter("@Username", SqlDbType.VarChar);
                    param.Value = Username;
                    cmd.Parameters.Add(param);
                    dr = cmd.ExecuteReader();
                    dt.Load(dr);
                }
                finally
                {
                    if (sqlConn != null)
                    {
                        sqlConn.Close();
                    }
                    if (dr != null)
                    {
                        dr.Close();
                    }
                }
            }
            return dt;
        }

        public static DataTable GetDeckDataByIdDeck(int IdDeck)
        {
            SqlDataReader dr = null;
            DataTable dt = new DataTable();
            using (SqlConnection sqlConn = GetConnection())
            {
                try
                {
                    sqlConn.Open();
                    SqlCommand cmd = new SqlCommand();
                    cmd.Connection = sqlConn;
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.CommandText = "spGetDeckDataByIdDeck";
                    SqlParameter param = new SqlParameter("@IdDeck", SqlDbType.Int);
                    param.Value = IdDeck;
                    cmd.Parameters.Add(param);
                    dr = cmd.ExecuteReader();
                    dt.Load(dr);
                }
                finally
                {
                    if (sqlConn != null)
                    {
                        sqlConn.Close();
                    }
                    if (dr != null)
                    {
                        dr.Close();
                    }
                }
            }
            return dt;
        }

        public static DataTable GetDeckDetailByIdDeck(int IdDeck)
        {
            SqlDataReader dr = null;
            DataTable dt = new DataTable();
            using (SqlConnection sqlConn = GetConnection())
            {
                try
                {
                    sqlConn.Open();
                    SqlCommand cmd = new SqlCommand();
                    cmd.Connection = sqlConn;
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.CommandText = "spGetDeckDetailByIdDeck";
                    SqlParameter param = new SqlParameter("@IdDeck", SqlDbType.Int);
                    param.Value = IdDeck;
                    cmd.Parameters.Add(param);
                    dr = cmd.ExecuteReader();
                    dt.Load(dr);
                }
                finally
                {
                    if (sqlConn != null)
                    {
                        sqlConn.Close();
                    }
                    if (dr != null)
                    {
                        dr.Close();
                    }
                }
            }
            return dt;
        }
    }
}
